import { createSlice } from "@reduxjs/toolkit";
//创建 slice 对象
let zanSlice = createSlice({
  name: 'zan',
  initialState: {value: 0},
  reducers: {
    //新增功能  {type: 'incre', payload: 1}
    incre: (state, action) => {
      //直接修改 state 的数据值即可更新状态
      state.value += action.payload;
    },
    //减少功能  {type: 'decre', payload: 1}
    decre: (state, action) => {
      state.value -= action.payload;
    }
  }
});

//获取 action creator
export let {incre, decre} = zanSlice.actions;

//获取 reducer 函数
let zanReducer = zanSlice.reducer;

export default zanReducer;   // {default: zanReducer, incre: incre, decre: decre}
